package com.tr.rentcar.model.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.tr.rentcar.model.GlobalParamHandler;
import com.tr.rentcar.model.bean.CarStyle;
import com.tr.rentcar.model.bean.CarUse;
import com.tr.rentcar.model.jdbc.MySqlDb;
import com.tr.rentcar.model.jdbc.ResultHandler;

public class CarStyleDao implements ResultHandler<CarStyle> {
	
	private MySqlDb db=MySqlDb.getInstance();
	@Override
	public CarStyle doHander(Map<String, Object> row) {
		CarStyle cs=new CarStyle();
		cs.setCsId(Integer.parseInt(row.get("cs_id")+""));
		cs.setCsName(row.get("cs_name")+"");
		return cs;
	}

	/**
	 * 获取全部车辆类型
	 * @throws SQLException 
	 */
	public List<CarStyle> getAll() throws SQLException{
		String sql="select * from car_style";
		return db.executeQuery(sql, this);
	}
	/*
	 通过名字找到该对象
	 */
	public CarStyle findbyname(String csname) throws SQLException{
		String sql="select * from car_style where cs_name=?";
		return db.queryUninResult(sql, new GlobalParamHandler(csname),this);
	}
	/**
	 * 添加记录
	 */
	public boolean insert(String name) throws SQLException{
		String sql="insert into car_style(cs_name) values(?)";
		return db.executeUpdate(sql, new GlobalParamHandler(name))>0;
	}
	/**
	 * 删除记录
	 */
	public boolean delete(Integer id) throws SQLException{
		String sql="delete  from car_style where cs_id=?";
		return db.executeUpdate(sql, new GlobalParamHandler(id))>0;
	}
}
